From dd746f40d76d4f6eca7b7495d58ec2b3a1a7ff25 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 16 Aug 2005 08:26:27 +0000 Subject: [PATCH] updated YCbCr coefficients --- ChangeLog | 7 +++++++ babl/base/model-ycbcr.c | 33 ++++++++++++++++++++------------- tests/rgb_to_ycbcr.c | 14 +++++++------- tests/rgb_to_ycbcr_to_rgb.c | 2 +- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed4f524..c5f9880 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-08-16 Øyvind Kolås + + * babl/base/mode-ycbcr.c: use coefficients from Charles Poyntes color + FAQ. + * tests/rgb_to_ycbcr_to_rgb.c: changed TOLERANCE to 0.00000000000001 + * tests/rgb_to_ycbcr.c: changed TOLERANCE as well as reference values. + 2005-08-16 Øyvind Kolås * babl/babl-fish.c: reindentation, no naming of fishes. diff --git a/babl/base/model-ycbcr.c b/babl/base/model-ycbcr.c index feb0d58..59a8518 100644 --- a/babl/base/model-ycbcr.c +++ b/babl/base/model-ycbcr.c @@ -94,15 +94,16 @@ rgb_to_ycbcr (int src_bands, double luminance, cb, cr; - luminance = 0.299 * red + - 0.587 * green + - 0.114 * blue; - cb = (-0.1687) * red - -0.3313 * green + - 0.5 * blue; - cr = 0.5 * red - -0.4187 * green + - -0.0813 * blue; + /* values taken from Charles Poynton's color FAQ + * http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC28 + * + * this is YPbPr not YCbCr to be exact, it uses the full range, maybe + * both should be included with babl under their proper name + * + */ + luminance = 0.299 * red +0.587 * green +0.114 * blue; + cb = -0.168736 * red -0.331264 * green +0.5 * blue; + cr = 0.5 * red -0.418688 * green -0.081312 * blue; *(double*)dst[0] = luminance; *(double*)dst[1] = cb; @@ -134,10 +135,16 @@ ycbcr_to_rgb (int src_bands, double red, green, blue; - red = luminance + 1.40200 * cr; - green = luminance - 0.34414 * cb - 0.71414 *cr; - blue = luminance + 1.77200 * cb; - + /* values taken from Charles Poynton's color FAQ + * http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC28 + * + * this is YPbPr not YCbCr to be exact, it uses the full range, maybe + * both should be included with babl under their proper name + * + */ + red = 1.0 * luminance + 0.0 * cb + 1.40200 * cr; + green = 1.0 * luminance - 0.344136 * cb - 0.71414136 * cr; + blue = 1.0 * luminance + 1.772 * cb + 0.0 * cr; *(double*)dst[0] = red; *(double*)dst[1] = green; diff --git a/tests/rgb_to_ycbcr.c b/tests/rgb_to_ycbcr.c index 4cbef79..a406457 100644 --- a/tests/rgb_to_ycbcr.c +++ b/tests/rgb_to_ycbcr.c @@ -23,7 +23,7 @@ #include "babl-internal.h" #define PIXELS 6 -#define TOLERANCE 0.000001 +#define TOLERANCE 0.00000000000001 float source_buf [PIXELS*3]= {0.0, 0.0, 0.0, @@ -34,12 +34,12 @@ float source_buf [PIXELS*3]= 0.0, 0.0, 1.0}; float reference_buf [PIXELS*3]= - {0.0, 0.0, 0.0, - 0.5, 0.0, 0.0, - 1.0, 0.0, 0.0, - 0.299,-0.1687, 0.5, - 0.587,-0.3313,-0.4187, - 0.114, 0.5, -0.081300}; + {0.0, 0.0, 0.0, + 0.5, 0.0, 0.0, + 1.0, 0.0, 0.0, + 0.299, -0.168736, 0.5, + 0.587, -0.331264, -0.418688, + 0.114, 0.5, -0.081312}; float destination_buf [PIXELS*3]; diff --git a/tests/rgb_to_ycbcr_to_rgb.c b/tests/rgb_to_ycbcr_to_rgb.c index d78ecb5..e9a0d1d 100644 --- a/tests/rgb_to_ycbcr_to_rgb.c +++ b/tests/rgb_to_ycbcr_to_rgb.c @@ -23,7 +23,7 @@ #include "babl-internal.h" #define PIXELS 6 -#define TOLERANCE 0.001 +#define TOLERANCE 0.00002 float source_buf [PIXELS*3]= {0.0, 0.0, 0.0, -- 2.30.2